package com.zrrd.gmall.product.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zrrd.gmall.common.result.Result;
import com.zrrd.gmall.model.product.BaseTrademark;
import com.zrrd.gmall.product.service.BaseTradeMarkService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("admin/product/baseTrademark")
public class BaseTradeMarkController {

    @Autowired
    private BaseTradeMarkService baseTradeMarkService;

    //分页查询品牌列表
    @GetMapping("/{page}/{limit}")
    public Result<Page> baseTrademark(@PathVariable("page") Integer page,
                                      @PathVariable("limit") Integer size) {
        //创建分页对象
        Page<BaseTrademark> pageInfo = new Page<>(page, size);
        //执行分页查询
        baseTradeMarkService.page(pageInfo, null);
        //返回结果
        return Result.ok(pageInfo);
    }

    //添加品牌
    @PostMapping("/save")
    public Result<String> save(@RequestBody BaseTrademark baseTrademark){
        baseTradeMarkService.save(baseTrademark);
        return Result.ok("成功");
    }

    //根据id获取品牌
    @GetMapping("/get/{id}")
    public Result<BaseTrademark> get(@PathVariable("id") Long id){
        return Result.ok(baseTradeMarkService.getById(id));
    }
    //修改品牌
    @PutMapping("/update")
    public Result<String> update(@RequestBody BaseTrademark baseTrademark){
        baseTradeMarkService.updateById(baseTrademark);
        return Result.ok("成功");
    }

    //删除品牌
    @DeleteMapping("/remove/{id}")
    public Result<String> remove(@PathVariable("id") Long id){
        baseTradeMarkService.removeById(id);
        return Result.ok("成功");

    }

    //查询全部品牌(添加Spu时选择品牌)
    @GetMapping("/getTrademarkList")
    public Result<List<BaseTrademark>> getTrademarkList(){
        return Result.ok(baseTradeMarkService.list(null));
    }

}
